/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.EstablishmentBean;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class CooperatorListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"CooperatorList.xls\"");
		HSSFSheet sheet = workbook.createSheet("list");
		HSSFRow r = sheet.createRow(0);
		r.createCell(0).setCellValue(new HSSFRichTextString("编号"));
		r.createCell(1).setCellValue(new HSSFRichTextString("名称"));
		r.createCell(2).setCellValue(new HSSFRichTextString("地区"));
		r.createCell(3).setCellValue(new HSSFRichTextString("电话"));
		r.createCell(4).setCellValue(new HSSFRichTextString("传真"));
		r.createCell(5).setCellValue(new HSSFRichTextString("Email"));
		r.createCell(6).setCellValue(new HSSFRichTextString("网站地址"));
		r.createCell(7).setCellValue(new HSSFRichTextString("邮编"));
		r.createCell(8).setCellValue(new HSSFRichTextString("地址"));
		r.createCell(9).setCellValue(new HSSFRichTextString("状态"));
		r.createCell(10).setCellValue(new HSSFRichTextString("备注"));
		r.createCell(11).setCellValue(new HSSFRichTextString("经办人"));
		List list = (List) model.get("list");

		for (int os = 0; os < list.size(); ++os) {
			EstablishmentBean bean = (EstablishmentBean) list.get(os);
			r = sheet.createRow(os + 1);
			String status = "";
			if (bean.getEstablishment().getStatus().equals("N")) {
				status = "停用";
			} else {
				status = "正常";
			}

			r.createCell(0)
					.setCellValue(
							new HSSFRichTextString(bean.getEstablishment()
									.getEstCode()));
			r.createCell(1)
					.setCellValue(
							new HSSFRichTextString(bean.getEstablishment()
									.getEstName()));
			r.createCell(2).setCellValue(
					new HSSFRichTextString(bean.getAreaName()));
			r.createCell(3).setCellValue(
					new HSSFRichTextString(bean.getEstablishment().getPhone()));
			r.createCell(4).setCellValue(
					new HSSFRichTextString(bean.getEstablishment().getFax()));
			r.createCell(5).setCellValue(
					new HSSFRichTextString(bean.getEstablishment().getEmail()));
			r.createCell(6)
					.setCellValue(
							new HSSFRichTextString(bean.getEstablishment()
									.getWebSite()));
			r.createCell(7).setCellValue(
					new HSSFRichTextString(bean.getEstablishment()
							.getPostcode()));
			r.createCell(8)
					.setCellValue(
							new HSSFRichTextString(bean.getEstablishment()
									.getAddress()));
			r.createCell(9).setCellValue(new HSSFRichTextString(status));
			r.createCell(10).setCellValue(
					new HSSFRichTextString(bean.getEstablishment().getMark()));
			r.createCell(11).setCellValue(
					new HSSFRichTextString(bean.getEstablishment()
							.getManagerName()));
		}

		ServletOutputStream arg10 = response.getOutputStream();
		workbook.write(arg10);
		arg10.flush();
		arg10.close();
	}
}